package mest.service.Modeling;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import mest.dao.Modeling.SubjectTypeDao;
import mest.entity.SubjectType;
import mest.util.ResultObj;
import mest.util.mestUtil;

/**
 *@Title SubjectTypeService.java
 *@description TODO
 *@time 2019年12月16日 下午7:20:45
 *@author Twinson Wong
 **/
@Service
@Transactional(rollbackFor=Exception.class)
public class SubjectTypeService {

	@Resource
	SubjectTypeDao subjectTypeDao;
	
	public List<SubjectType> selectAll(Map<String, Object> map) {
		return subjectTypeDao.selectAll(map);
	}
	
	public int count(Map<String, Object> map) {
		return subjectTypeDao.count(map);
	}

	public ResultObj insert(Map<String, Object> map) {
		try {
			subjectTypeDao.insert(map);
			return  ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
				return ResultObj.createErrorMsg("数据已存在");
			}
			return ResultObj.createErrorMsg(ResultObj.ERROR);
		}
	}

	public ResultObj update(Map<String, Object> map) {
		try {
			subjectTypeDao.update(map);
			return  ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
				return ResultObj.createErrorMsg("数据已存在");
			}
			return ResultObj.createErrorMsg(ResultObj.ERROR);
		}
	}
	
	public int delete(Map<String, Object> map) {
		return subjectTypeDao.delete(map);
	}
}
